home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Utilities / InstallerMaker™ / InstallerMaker__2.0.2_Installe / InstallerMaker™ 2.0.2 Installer / InstallerMaker Extensions / IMid Extension / IMid.p < prev    next >
Text File  |  1994-05-03  |  8KB  |  255 lines

  1. (* ****************************************************************
  2.  
  3.         IMid.p        Translated to MPW Pascal by Jim Merritt (jam)
  4.                     based on an original C routine by Raymond Lau.
  5.                     
  6.         Copyright © 1993 Aladdin Systems, Inc. & Raymond Lau.
  7.         All Rights Reserved.
  8.         
  9.         In combination with the associated make file (IMid.make),
  10.         this source text produces an IMid installer extension, which
  11.         can be called by a Product Installer during the installation
  12.         process.  Specifications for IBeg, IMid, ICnd, and IEnd
  13.         installer extensions are given in the documentation for
  14.         StuffIt InstallerMaker™.
  15.         
  16.         In the absence of the folder manager (typically on System 6),
  17.         this subroutine will:
  18.            
  19.         • Put any Aladdin folder within the :System:Extensions folder,
  20.           creating the Extensions folder if necessary.
  21.         • Put any file of types 'appe' or 'thng' into the
  22.           :System:Extensions folder, creating the Extensions folder if
  23.           necessary.
  24.         • Put files of type 'Pref' and 'pref' into the :System:Preferences
  25.           folder, creating the Preferences folder if necessary.
  26.         
  27.         CHANGE HISTORY:
  28.         
  29.         VER    DATE        ENGR    DESCRIPTION
  30.         1    93.06.08    jam        Initial version, based on Lau's
  31.                                 original in C.
  32.         2    93.06.16    jam        Pascal definitions of code resources were
  33.                                 changed to replace BOOLEAN parameters and
  34.                                 function return values with INTEGERs, and
  35.                                 also to replace enumeration types and SETs
  36.                                 with INTEGERs.  This was made necessary
  37.                                 when we discovered that certain Pascal
  38.                                 compilers used very eccentric enumeration
  39.                                 mechanisms, which were profoundly
  40.                                 incompatible with the original C definitions
  41.                                 at the machine-code level.  The best
  42.                                 compromise was to fall back to INTEGERs.
  43.         3    93.06.17    jam        Introduced and made slight modifications to
  44.                                 mag's routine, BlessedFldrSpec, replacing
  45.                                 rl's original GetSysVolDir routine (from C
  46.                                 version).  Customers should compare
  47.                                 GetSysVolDir and BlessedFolderSpec to see
  48.                                 differences between low-level and higher-
  49.                                 level coding to achieve the same ends.
  50.                                 
  51.                                 Rewrote code to change ensure that sense of
  52.                                 FindFolderInSystem is always positive logic.
  53.                                 
  54.         4    93.06.28    jam        Changed to support 'thng' file type, per
  55.                                 changes to Lau’s C version.
  56.         5    94.03.14    jam        Changed DoWhileInstalling to support new
  57.                                 "packages" parameter.
  58.         6    94.05.03    jam        Changed DoWhileInstalling to support new
  59.                                 "after" parameter.
  60.  
  61. ****************************************************************** *)
  62. (*$Z+*) (*    Allows linker to find DoWhileInstalling without declaring it
  63.             in the interface *)
  64. UNIT IMid;
  65.  
  66. INTERFACE (* empty -- see $Z directive, above *)
  67.  
  68. IMPLEMENTATION
  69.     (*    Putting a subroutine within a UNIT that has an empty
  70.         IMPLEMENTATION is an oft-used method for creating
  71.         a standalone code-resource in MPW Pascal.
  72.     *)
  73.  
  74. (* *********************** INCLUDES *************************** *)       
  75.  
  76.     USES    Types,
  77.             ToolUtils,    (* for BitAnd *)
  78.             Folders,
  79.             OSUtils,    (* for EqualString *)
  80.             Files,        (* for HParamBlockRec *)
  81.             GestaltEqu    (* for Gestalt *);
  82.  
  83.  
  84. CONST
  85.   EmptyString= '';
  86.     
  87.   (* For using INTEGERs as if they were BOOLEANs *)
  88.   IntFALSE= 0;
  89.   IntTRUE= 1;  (* (x <> IntFALSE) should be used to test for IntTRUE *)
  90.       (* Use the constant IntTRUE only when you desire to assign a TRUE
  91.        value to an INTEGER.
  92.     *)
  93.  
  94.   (* Return and parameter values for various INTEGER items *)
  95.   (* For ICnd, IMid *)
  96.   OKToContinue= 0; (* For ICnd, IMid *)
  97.   SkipThisItem= 1; (* For ICnd, IMid *)
  98.   CancelInstallation= 2; (* For IMid only *)
  99.  
  100.   (* For IBeg, IEnd *)
  101.   WasNOTAborted= 0;
  102.   WasAborted= 1;
  103.  
  104. (* FindFolderInSystem must be FORWARD because DoWhileInstalling MUST
  105.     be the first routine that has a code body.
  106. *)
  107. FUNCTION FindFolderInSystem(name: str255; VAR vol: INTEGER;
  108.                             VAR dir: LongInt): BOOLEAN; FORWARD;
  109.  
  110. FUNCTION DoWhileInstalling(    userVol: INTEGER;
  111.                 userDir: LongInt;
  112.                 VAR destVol: INTEGER;
  113.                 VAR destDir: LongInt;
  114.                 isFolder: INTEGER;
  115.                   VAR name: Str255;
  116.                 creationDate: LongInt;
  117.                 modificationDate: LongInt;
  118.                 ftype, fcreator: OSType;
  119.                 packages: INTEGER;
  120.                 after: INTEGER): INTEGER;
  121.  
  122.   VAR
  123.     gest: LongInt;
  124.     result: INTEGER;
  125. BEGIN (* DoWhileInstalling *)
  126.     result := OKToContinue;
  127.     IF (after = IntFALSE) THEN BEGIN (* Only execute this BEFORE the file
  128.                                         is installed. *)
  129.     (* IF FindFolder is present THEN ... *)
  130.     IF (Gestalt(gestaltFindFolderAttr,gest) <> noErr) (* does gestalt exist? *)
  131.     THEN IF (NOT (BAND(gest,BitShift(1, gestaltFindFolderPresent)) <> 0))
  132.             (* is the FindFolder avail bit set? *)
  133.         THEN BEGIN
  134.         IF (isFolder <> IntFALSE) THEN BEGIN
  135.             IF (EqualString(name,'Aladdin',FALSE,TRUE)) THEN
  136.                 BEGIN
  137.                 IF (NOT FindFolderInSystem('Extensions', destVol, destDir))
  138.                     THEN result := CancelInstallation;
  139.                 (*    If FindFolderInSystem succeeds, it changes destVol and
  140.                     destDir, thus redirecting the item under consideration
  141.                     to the specified folder.  (In other words, the IMid
  142.                     changes the destination path before the Product
  143.                     Installer writes the item to the target.)
  144.                 *)
  145.                 END
  146.                 
  147.             END ELSE BEGIN
  148.             IF ((ftype = 'appe') OR (ftype = 'thng')) THEN BEGIN
  149.                 IF (NOT FindFolderInSystem('Extensions',destVol,destDir))
  150.                     THEN result := CancelInstallation;
  151.             END ELSE IF ((ftype = 'Pref') OR (ftype = 'pref')) THEN BEGIN
  152.                 IF (NOT FindFolderInSystem('Preferences',destVol,destDir))
  153.                     THEN result := CancelInstallation;
  154.             END;
  155.         END;
  156.  
  157.     END;
  158.     END (* Guard to make sure we are executing
  159.            before the file is installed. *);
  160.     DoWhileInstalling := result;
  161. END (* DoWhileInstalling *);
  162.  
  163. FUNCTION BlessedFldrSpec (  VAR vRefNum: integer; VAR dirID: longint; 
  164.                             VAR name: Str255 ): OSErr;
  165. (* Should take every possible way of finding the blessed folder.
  166.    On ENTRY, values of vRefNum, dirID, and name are undefined.
  167.    On EXIT,
  168.      A return code of noErr, means that vRefNum, dirID and name
  169.      contain a complete path specification for the blessed
  170.      folder (not necessarily named 'System'!).
  171.      
  172.      Any other return code leaves the contents of vRefNum, dirID, and
  173.      name undefined, and possibly altered from their entry states.
  174. *)
  175.     CONST
  176.         kSync= FALSE;                (* call File System synchronously *)
  177.     VAR
  178.       theWorld:    SysEnvRec;
  179.       error:    OSErr;
  180.       wdpb:        WDPBRec;
  181.       cipb:        CInfoPBRec;
  182.  
  183.     BEGIN (* BlessedFldrSpec *)
  184.         name :=     EmptyString;
  185.         vRefNum :=     0;
  186.         dirID :=     0;
  187.         
  188.         error :=    SysEnvirons(1,theWorld);
  189.  
  190.         (* prepare wdpb for PBGetWDInfo *)
  191.         wdpb.ioCompletion :=    NIL;
  192.         wdpb.ioVRefNum :=        theWorld.sysVRefNum;
  193.         wdpb.ioWDIndex :=         0;            (* use ioVRefNum    *)
  194.         wdpb.ioWDProcID :=         0;
  195.         wdpb.ioWDVRefNum :=     0;
  196.         
  197.         wdpb.ioNamePtr :=        NIL;        (* be clean about it    *)
  198.         wdpb.ioWDDirID :=        0;
  199.         wdpb.ioResult :=        noErr;
  200.         
  201.         error := PBGetWDInfo(@wdpb, FALSE);
  202.         
  203.         if (error = noErr)
  204.             THEN BEGIN
  205.                 vRefNum :=    wdpb.ioWDVRefNum;
  206.                 dirID :=    wdpb.ioWDDirID;
  207.         
  208.                 (* fill cipb for PBGetCatInfo *)
  209.                 cipb.ioCompletion :=    NIL;
  210.                 cipb.ioNamePtr :=        @name;    (* File System fills this in    *)
  211.                 cipb.ioVRefNum :=        vRefNum;
  212.                 cipb.ioFDirIndex :=        -1;        (* get name using vRefNum, dirID *)
  213.                 cipb.ioDirID :=            dirID;
  214.                 error := PBGetCatInfo(@cipb, kSync);
  215.         
  216.                 if (error <> noErr) THEN name := EmptyString;
  217.             END;
  218.         
  219.         BlessedFldrSpec := error;
  220.     END        (* BlessedFldrSpec *);
  221.  
  222. FUNCTION FindFolderInSystem(* name: str255; VAR vol: INTEGER;
  223.                             VAR dir: LongInt): BOOLEAN *);
  224. (* On ENTRY, if the specified system subfolder does not
  225.      exist,  routine attempts to create it.
  226.    On EXIT, returns TRUE if the specified system subfolder
  227.      exists, and FALSE if not (even despite attempts at
  228.      creation).  When TRUE, vol and dir specify the folder.
  229. *)
  230.     VAR
  231.         sysvol: INTEGER;
  232.         sysdir: LongInt;
  233.         HRec: HParamBlockRec;
  234.         FFISname: Str255;
  235.         FFISError: OSErr;
  236. BEGIN (* FindFolderInSystem *)
  237.     FFISError := BlessedFldrSpec(sysvol, sysdir, FFISname);
  238.     IF (FFISError <> noErr)
  239.       THEN BEGIN FindFolderInSystem := FALSE
  240.       END ELSE BEGIN
  241.         HRec.ioNamePtr := @name;
  242.         HRec.ioVRefNum := sysvol;
  243.         HRec.ioDirID := sysdir;
  244.         IF (PBDirCreateSync(@HRec) <> noErr) THEN BEGIN
  245.             FindFolderInSystem := FALSE;
  246.         END ELSE BEGIN
  247.             vol := sysvol;
  248.             dir := HRec.ioDirID;
  249.             FindFolderInSystem := TRUE;
  250.         END;
  251.     END (* IF-THEN-ELSE *);
  252. END (* FindFolderInSystem *);
  253.  
  254.  
  255. END (* IMid *).